package com.leyou.item.service;

import com.leyou.item.pojo.Category;
import com.leyou.item.mapper.CategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author shkstart
 * @create 2020-03-23 1:15
 */
@Service
public class CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    /**
     * 根据parentId查询子类目
     * @param pid
     * @return
     */
    public List<Category> queryCategoriesByPid(Long pid) {
        Category record = new Category();
        record.setParentId(pid);
        return categoryMapper.select(record);
    }

    public List<Category> queryCategoriesByBid(Long bid) {

       return categoryMapper.queryCategoriesByBid(bid);
    }

    public List<String> getCategoryNamesById(List<Long> ids) {
        List<String> strings = new ArrayList<>();
        List<Category> list = categoryMapper.selectByIdList(ids);
        list.forEach(s->{
            strings.add(s.getName());
        });
        return strings;
    }
}
